﻿using Microsoft.Win32;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Linq;
using Tools.Core;

namespace Tools.Modules.Navigations.ViewModels
{
    public class AdvanceImageOCRViewModel : BindableBase,INavigationAware
    {
        private string _current=string.Empty;
        public string Current
        {
            get => _current;
            set=>SetProperty(ref _current, value);
        }
        private string _result=string.Empty;
        public string Result
        {
            get=>_result;
            set=>SetProperty(ref _result, value);
        }
        public DelegateCommand ChooseImageCommand { get; private set; }
        public DelegateCommand CatchImageCommand { get; private set; }
        public DelegateCommand RecognizeTextCommand { get; private set; }
        public DelegateCommand RecognizeTableCommand { get; private set; }
        public AdvanceImageOCRViewModel()
        {
            ChooseImageCommand = new DelegateCommand(() => 
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Filter = "图片文件|*.jpg;*.png;*.gif;*.bmp;*.tiff";
                if (ofd.ShowDialog() == true)
                {
                    Current= ofd.FileName;
                }
            });
            CatchImageCommand = new DelegateCommand(() =>
            {

            });
            RecognizeTableCommand = new DelegateCommand(() =>
            {
                Result = Softwares.OCRTable(Current);
            });
            RecognizeTextCommand = new DelegateCommand(() =>
            {
                Result = Softwares.OCRText(Current);
            });
        }

        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return true;
        }

        public void OnNavigatedFrom(NavigationContext navigationContext)
        {
        }

        public void OnNavigatedTo(NavigationContext navigationContext)
        {
        }
    }
}
